﻿//********************************************************************************//
//创建日期：<创建日期，2016-09-20>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：专灌计划 专灌计划下达
//********************************************************************************//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Platform.Http;
using System.Text;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS.JiHuaGL.ZhuanGuanJH
{
    public partial class ZhuanGuanJHXD : System.Web.UI.Page
    {
        #region 属性

        #endregion

        #region 变量
        /// <summary>
        /// 存储过程执行类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        /// <summary>
        /// 参数bll
        /// </summary>
        QS_CANSHUBBLL _CANSHUBLL = new QS_CANSHUBBLL();

       
        /// <summary>
        /// 专灌计划bll
        /// </summary>
        QS_JH_ZHUANGUANJHBLL _ZGJHBLL = new QS_JH_ZHUANGUANJHBLL();
        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
            }

        }

        /// <summary>
        /// 绑定空表头
        /// </summary>
        protected override void Render(HtmlTextWriter sender)
        {
            base.Render(sender);
        }



        /// <summary>
        /// 放弃
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            InitData();
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            //int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            int year = Convert.ToInt32(txtV.Text.Trim());
            string msg = "";
            if (e.Parameter == "yz1")
            {
                DataTable dt = _ZGJHBLL.SelectQS_JH_ZHUANGUANJHsDynamic(string.Format("I_Y={0} and i_jlzt=0", txtV.Text.Trim()), null);
                if (dt.Rows.Count > 0)
                {
                    msg = "true";
                }
                else
                {
                    msg = "false";
                }
                e.Result = e.Parameter + "|0|" + msg;
            }
            else if (e.Parameter == "yz2")
            {
                //根据sname 是否 采灌井，以及年份来判断是否用户都已经制定计划
                string result = "";
                _SpHelper.P_QSJH_JIHUAGLXD("专灌井", year.ToString(), out result);
                msg = result == "0" ? "true" : "false";
                e.Result = e.Parameter + "|0|" + msg;
            }
            else if (e.Parameter == "xdjh")
            {
                //下达采灌计划
                _SpHelper.P_QSJH_XIADAJH(2,year, out msg);//1 下达成功
                e.Result = e.Parameter + "|0|" + msg;
            }

        }
        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            string year = "";
            string year1 = "";
            string year2 = "";
            _SpHelper.P_QSJH_MAXYEAR("QS_JH_ZHUANGUANJH", out year1);
            DataTable dt = _CANSHUBLL.SelectQS_CANSHUBsDynamic(string.Format("i_jlzt=0 and S_MINGCHENG='WaterYear' or S_MIAOSHU='水量年'"), null);
            year2 = dt.Rows.Count > 0 ? dt.Rows[0]["S_ZHI"].ToString() : "";
            if (year1 == "" || year1 == null)
            {
                year = year2;
            }
            else
            {
                year = (Convert.ToInt32(year1) + 1).ToString();
            }
            if (Convert.ToInt32(year) <= (Convert.ToInt32(year2) + 1))
            {
                txtV.Text = year;
            }
            else
            {
                txtV.Text = "";
            }
        }
        #endregion        
    }
}